from django.db import models

# Create your models here.
SEX_CHOICES = [
    ('男', '男'),
    ('女', '女'),
]
ORDER_STATUS = (
    ("TRADE_SUCCESS", "支付成功"),
    ("TRADE_CLOSED", "超时关闭"),
    ("WAIT_BUYER_PAY", "交易创建"),
    ("TRADE_FINISHED", "交易结束"),
    ("PAYING", "待支付"),
)

PAY_TYPE = (
    ("alipay", "支付宝"),
    ("wechat", "微信"),
)
class UserProfile(models.Model):
    id = models.AutoField(primary_key=True)
    user_ip = models.GenericIPAddressField(null=True,blank=True)
    user_birthday_date = models.DateField(verbose_name='出生日期')
    user_birthday_time = models.TimeField(verbose_name='出生时间')
    user_sex=models.CharField(choices=SEX_CHOICES,default='男',verbose_name='性别',max_length=10)
    address=models.CharField(max_length=100,verbose_name='出生地区',null=True,blank=True)
    search_type=models.CharField(max_length=100,verbose_name='查询类型',null=True,blank=True)
    add_time=models.DateTimeField(auto_now_add=True,verbose_name='提交时间')
    is_paid = models.BooleanField(default=False, verbose_name="是否支付")
    content = models.TextField(verbose_name='预测信息',null=True,blank=True)

    # 订单号唯一
    order_sn = models.CharField("订单编号", max_length=30, null=True, blank=True, unique=True)
    # 支付宝交易号
    trade_no = models.CharField("交易号", max_length=100, unique=True, null=True, blank=True)
    # 支付状态,default="PAYING"只能是字符串
    pay_status = models.CharField("订单状态", choices=ORDER_STATUS, default="PAYING", max_length=30)
    # 订单的支付类型
    pay_type = models.CharField("支付类型", choices=PAY_TYPE, default="alipay", max_length=10)
    order_mount = models.DecimalField("订单金额", max_digits=10, decimal_places=2,null=True, blank=True)
    pay_time = models.DateTimeField("支付时间", null=True, blank=True)

    class Meta:
        db_table = 'y_user'
        verbose_name = '用户订单信息'
        verbose_name_plural = '用户订单信息'

    def __str__(self):
        return f"{self.user_ip}的表单数据"

